package cn.didi.feidi.androidorder.assembly;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.didi.feidi.androidorder.R;

/**
 * Created by dugu on 2017/8/31.
 */

public class PersonReturnDepositBucketInputPopupWindow extends PopupWindow {

    private ImageView quitInput;
    private TextView waterMarketName;
    private EditText returnBucketNum;
    private TextView nextStep;

    private View mMenuView;

    public PersonReturnDepositBucketInputPopupWindow(Activity context, View.OnClickListener itemsOnClick , View.OnClickListener closeOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mMenuView = inflater.inflate(R.layout.fragment_return_deposit_dialog_input, null);

        quitInput = (ImageView) mMenuView.findViewById(R.id.quit_input_blank_bucket_text_iv);
        waterMarketName = (TextView) mMenuView.findViewById(R.id.person_return_deposit_dialog_water_market_name);
        returnBucketNum = (EditText) mMenuView.findViewById(R.id.person_return_deposit_blank_bucket_number_input);
        nextStep = (TextView) mMenuView.findViewById(R.id.person_return_deposit_next_step);

        quitInput.setOnClickListener(closeOnClick);
//        waterMarketName.setOnClickListener(itemsOnClick);
//        returnBucketNum.setOnClickListener(itemsOnClick);
        nextStep.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.popup_window_anim);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView.findViewById(R.id.person_rerurn_deposit_parent_view).getTop();
                int y=(int) event.getY();
                if(event.getAction()== MotionEvent.ACTION_UP){
                    if(y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });

    }

    public PersonReturnDepositBucketInputPopupWindow setWaterStoreName(String waterStoreName){
        if (waterMarketName!=null){
            waterMarketName.setText(waterStoreName);
        }
        return this;
    }

    public String getBucketNum(){
        return returnBucketNum.getText().toString().trim();
    }

}
